package com.genghis.rapidcrm.web.view.model;

import com.genghis.rapidcrm.kernel.RapidLinkModel;
import edu.jetwinner.common.EasyStringUtil;
import org.springframework.beans.BeanUtils;

/**
 * @author xulixin
 */
public class RapidJsScriptModel extends BaseScriptModel {

    public static RapidJsScriptModel getInstanceFromLinkObject(RapidLinkModel linkModel) {
        RapidJsScriptModel scriptModel = new RapidJsScriptModel();
        BeanUtils.copyProperties(scriptModel, linkModel);
        return scriptModel;
    }


    private static final String DEFAULT_TYPE = "text/javascript";

    private String src;
    private String type;

    /**
     * Function to get the type attribute value
     *
     * @return <String>
     */
    public String getType() {
        if(EasyStringUtil.isBlank(this.type)){
            this.type = DEFAULT_TYPE;
        }
        return this.type;
    }

    /**
     * Function to get the src attribute value
     * @return <String>
     */
    public String getSrc() {
        if(EasyStringUtil.isBlank(this.src)) {
            this.src = this.getLinkUrl();
        }
        return this.src;
    }

    public RapidJsScriptModel setSrc(String src) {
        this.src = src;
        return this;
    }

    public RapidJsScriptModel setType(String type) {
        this.type = type;
        return this;
    }
}
